package com.fss.experience.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fss.common.dao.CommonDao;
import com.fss.experience.dao.ExperienceDao;
import com.fssDataModels.TbComment;
import com.fssDataModels.TbExperience;
import com.fssDataModels.TbExperienceType;
import com.fssDataModels.TbUser;
import com.opensymphony.xwork2.ActionContext;

public class ExperienceServiceImpl implements ExperienceService {
	private ExperienceDao experienceDao;
	private CommonDao commonDao;
	@Override
	public List<TbExperienceType> getExperienceTypeList() {
		return this.commonDao.getExperienceTypes();
	}
	@Override
	public List<TbExperience> getExperienceList() {
		return this.commonDao.getExperiences(null, null, new Date());
	}
	@Override
	public List<TbExperience> getExperiecneList(int typeId,
			Date fromDate, Date toDate) {
		TbExperienceType experienceType = this.experienceDao.getExperienceType(typeId);
		return this.commonDao.getExperiences(experienceType, fromDate, toDate);
		
	}
	@Override
	public TbExperience getExperienceById(int experienceId) {
		return this.experienceDao.getExperience(experienceId);
	}
	@Override
	public int deleteExperience(TbExperience experience) {
		
		return this.experienceDao.deleteExperience(this.experienceDao.getExperience(experience.getExperienceId()));
	}
	@Override
	public int editExperience(TbExperience experience) {
		experience.setCreatedTime(new Date());
		Map session = ActionContext.getContext().getSession();
		experience.setTbUser((TbUser) session.get("user_login"));
		return	this.experienceDao.updateExperience(experience);
	}
	
	
	@Override
	public List<TbComment> getCommentList(TbExperience experience) {
		return this.experienceDao.getComments(experience);
	}
	
	
	
	@Override
	public void addComment(TbExperience experience, TbComment comment) {
		comment.setCreatedTime(new Date());
		Map session = ActionContext.getContext().getSession();
		comment.setGeneratorName(((TbUser) session.get("user_login")).getDisplayName());
		
		this.experienceDao.addComment(experience, comment);
	}
	
	@Override
	public int addExperience(TbExperience experience) {
		experience.setCreatedTime(new Date());
		
		Map session = ActionContext.getContext().getSession();
		experience.setTbUser((TbUser) session.get("user_login"));
		return	this.experienceDao.insertExperience(experience);
	}
	public ExperienceDao getExperienceDao() {
		return experienceDao;
	}
	public void setExperienceDao(ExperienceDao experienceDao) {
		this.experienceDao = experienceDao;
	}
	public CommonDao getCommonDao() {
		return commonDao;
	}
	public void setCommonDao(CommonDao commonDao) {
		this.commonDao = commonDao;
	}

	
	
	
	
}